import React, {useState} from "react";
import {
    BrowserRouter as Router,
    Switch,
    Route,
    Redirect,
} from "react-router-dom";
import {TransitionGroup, CSSTransition} from 'react-transition-group'
import Center from "../pages/center/center";
import Home from "../pages/home/home";
import Talk from "../pages/talk/talk";
import Login from "../pages/login/login";
import Register from "../pages/login/register";
import "../style/router.less";
import stores from "../store";

// function RouterCreate(props) {
//     return !props.login.isLogin ? <Redirect to="/login"/> : <Route path={props.path} component={props.component}/>
// }
const  routes = [
    {path: '/', name: 'Home', exact:true, Component: Home},
    {path: '/center', name: 'center', exact:false, Component: Center},
    {path: '/talk', name: 'talk', exact:false, Component: Talk},
    {path: '/login', name: 'login',  exact:false,Component: Login},
    {path: '/register', name: 'register',  exact:false,Component: Register},
]
class router extends React.Component{
    constructor(props){
        super(props);
        this.state={
            show:true,
        }
    }
    render(): React.ReactElement<any, string | React.JSXElementConstructor<any>> | string | number | {} | React.ReactNodeArray | React.ReactPortal | boolean | null | undefined {
        return (
            <Router>
                {routes.map(({ path,exact, Component }) =>{
                    return  <Route key={path} exact={exact} path={path} render={(props)=>{
                        return <CSSTransition
                            in={true}
                            timeout={300}
                            classNames="page"
                            appear={true}
                            unmountOnExit
                        >
                            <div className="routerPage">
                                <Component {...props}  />
                            </div>
                        </CSSTransition>
                    }}/>
                })}
            </Router>
        )
    }


}

export default router;
